{extend name="default:layout:base" /}

{block name="main"}
<div class="layui-row" style="margin: 10px;">
    <div class="layui-col-xs3 layui-col-xs-offset9 text-right">
        <a href="{:url('choose')}" class="layui-btn layui-btn-sm layui-btn-normal">新建版本</a>
    </div>
    {if $real_version_info}
    <br><br>
    <div class="layui-col-xs12">
        <blockquote class="layui-elem-quote">
            线上真实版本信息：
            <p>{$real_version_info.release_version}</p>
            <p>{$real_version_info.release_desc}</p>
        </blockquote>
    </div>
    {/if}
</div>

<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <ul class="layui-tab-title">
        <li class="layui-this">
            <a href="{:url('index')}">版本管理</a>
        </li>
        <li>
            <a href="{:url('log')}">历史版本</a>
        </li>
    </ul>

    <div class="layui-tab-content">
        <div class="inner">
            <div class="line">
                <div class="title">线上版本</div>
                <?php if($publish):?>
                <div class="layui-row">
                    <div class="layui-col-xs3 col1">
                        <img src="{$publish.logo}" alt="" class="addon-logo">
                    </div>
                    <div class="layui-col-xs6">
                        <p class="info-item">
                            <span class="label">应用：</span>
                            <span class="value">{$publish.name}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">版本：</span>
                            <span class="value">{$publish.user_version}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">描述：</span>
                            <span class="value">{$publish.user_desc}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">发布时间：</span>
                            <span class="value">{:date('Y-m-d H:i:s', $publish.publish_time)}</span>
                        </p>
                    </div>
                    <div class="layui-col-xs3">
                        <button class="layui-btn layui-btn-sm layui-btn-normal js-revert" data-id="{$publish.id}">版本回退</button>
                    </div>
                </div>
                <?php else:?>
                <div class="empty-box">
                    <p class="empty-tips">
                        你暂无发布版本
                    </p>
                </div>
                <?php endif;?>
            </div>

            <div class="line">
                <input type="hidden" id="verifyId" value="1">
                <div class="title">审核版本</div>
                <?php if($verify):?>
                <div class="layui-row">
                    <div class="layui-col-xs3 col1">
                        <img src="{$verify.logo}" alt="" class="addon-logo">
                        <p>
                            {if $verify['status'] == 2}
                            <span class="layui-badge layui-bg-green">审核通过</span>
                            {elseif $verify['status'] == 3}
                            <span class="layui-badge">审核失败</span>
                            {else/}
                            <span class="layui-badge layui-bg-orange">审核中...</span>
                            <i class="fa fa-refresh js-get-audit-status"
                               title="刷新审核进度"
                               style="color: #9a9a9a"
                               data-auditid="{$verify.audit_id}"
                            ></i>
                            {/if}
                        </p>
                    </div>
                    <div class="layui-col-xs6">
                        <p class="info-item">
                            <span class="label">应用：</span>
                            <span class="value">{$verify.name}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">版本：</span>
                            <span class="value">{$verify.user_version}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">描述：</span>
                            <span class="value">{$verify.user_desc}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">提交审核时间：</span>
                            <span class="value">{:date('Y-m-d H:i:s', $verify.verify_time)}</span>
                        </p>
                        {if $verify['status'] == 3}
                        <p class="info-item">
                            <span class="label">失败原因：</span>
                            <span class="value">{$verify.reason|raw}</span>
                        </p>
                        {/if}
                    </div>
                    <div class="layui-col-xs3">
                        <?php if($verify['status'] == 1):?>
                        <button class="layui-btn layui-btn-sm js-speedup-audit" data-auditid="{$verify.audit_id}">加急审核</button>
                        <button class="layui-btn layui-btn-sm layui-btn-normal js-cancel-audit" data-id="{$verify.id}">撤回</button>
                        <?php elseif($verify['status'] == 2):?>
                        <button class="layui-btn layui-btn-sm js-publish" data-id="{$verify.id}">提交发布</button>
                        <?php endif;?>
                    </div>
                </div>
                <script>
                    //有审核版本时，自动刷新一次
                    (function isWindowActive() {
                        var userAgent = navigator.userAgent;
                        var isIE = userAgent.indexOf('Trident') > -1;
                        if(isIE){
                            $(window).focus(function () {
                                location.reload();
                            })
                        }else{
                            var bowhidden="hidden" in document?"hidden": "webkithidden" in document?"webkithidden": "mozhidden" in document ?"mozhidden": null;
                            var vibchage="visibilitychange" || "webkitvisibilitychange" || "mozvisibilitychange";
                            document.addEventListener(vibchage,function () {
                                if(!document[bowhidden])  location.reload();
                            });
                        }
                        return false;
                    })();
                </script>
                <?php else:?>
                <div class="empty-box">
                    <p class="empty-tips">
                        你暂无提交审核的版本或者版本已发布上线
                    </p>
                </div>
                <?php endif;?>
            </div>

            <div class="line">
                <div class="title">当前选择版本</div>
                <?php if($current):?>
                <div class="layui-row">
                    <div class="layui-col-xs3 col1">
                        <img src="{$current.logo}" alt="" class="addon-logo">
                        <p>
                            <button data-id="{$current.id}" data-src="{$current.qr_code}" class="js-view-demo layui-btn layui-btn-xs">体验码</button>
                        </p>
                    </div>
                    <div class="layui-col-xs6">
                        <p class="info-item">
                            <span class="label">应用：</span>
                            <span class="value">{$current.title}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">版本：</span>
                            <span class="value">{$current.user_version}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">描述：</span>
                            <span class="value">{$current.user_desc}</span>
                        </p>
                        <p class="info-item">
                            <span class="label">提交时间：</span>
                            <span class="value">{$current.create_time}</span>
                        </p>
                    </div>
                    <div class="layui-col-xs3">
                        <?php if($current['status'] == 0):?>
                        <button class="layui-btn layui-btn-sm layui-btn-normal js-audit" data-id="{$current.id}">提交审核</button>
                        <?php else:?>
                        <button class="layui-btn layui-btn-sm layui-btn-disabled">提交审核</button>
                        <?php endif;?>
                    </div>
                </div>
                <?php else:?>
                <div class="empty-box">
                    <p class="empty-tips">你暂未提交版本</p>
                </div>
                <?php endif;?>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    //提交审核后的回调函数
    function closeAuditWindow(){
        location.reload();
    }

    layui.use(['jquery', 'layer'], function () {
        var $ = layui.jquery,
                layer = layui.layer;
        /**
         * 加急审核
         */
        $('.js-speedup-audit').on('click', function () {
            requestPost("{:url('speedupAuditPost')}", {auditid: $(this).data('auditid')});
        });
        /**
         * 点击发布
         */
        $('.js-publish').on('click', function () {
            var id = parseInt($(this).data('id'));
            layer.confirm('你确定发布吗？', {}, function () {
                requestPost("{:url('releasePost')}", {id: id}, function () {
                    location.reload();
                });
            });
        });

        /**
         * 撤销审核
         */
        $('.js-cancel-audit').on('click', function () {
            layer.confirm('单个帐号每天审核撤回次数最多不超过1次，一个月不超过10次。确定操作吗？', {}, function () {
                requestPost("{:url('cancelAuditPost')}", {id: $(this).data('id')}, function (res) {
                    location.reload();
                });
            });
        });

        /**
         * 刷新审核信息
         */
        $('.js-get-audit-status').on('click', function () {
            requestPost("{:url('getAuditStatusPost')}", {auditid: $(this).data('auditid')}, function (res) {
                location.reload();
            })
        });

        //点击提交审核
        $('.js-audit').on('click', function () {
            layer.open({
                type: 2,
                title: '审核项配置',
                shadeClose: false,
                shade: 0.8,
                area: ['800px', '506px'],
                content: ['{:url("commitaudit")}?log_id=' + $(this).data('id'), 'no']
            });
        });

        //点击体验码
        $('.js-view-demo').on('click', function () {
            var src = $(this).data('src')
                    ,id = parseInt($(this).data('id'));
            if(src === ''){
                requestPost("{:url('getTestQrCode')}", {id: id}, function (res) {
                    src = res.data.src;
                    layer.photos({
                        photos: {
                            "data": [  {"src": src}]
                        }
                    });
                });
            }else{
                layer.photos({
                    photos: {
                        "data": [ {"src": src}]
                    }
                });
            }
        });
    })
</script>
{/block}

{block name="css"}
<style>
    .content {
        background: #FAFAFA;
    }

    .layui-tab-content .line {
        margin-bottom: 30px;
        background-color: #fff;
        border-radius: 4px;
        box-shadow: 0 1px 2px rgba(150,150,150,0.3);
        padding: 20px 30px 30px;

    }
    .layui-tab-content .line .col1{
        text-align: center;
    }
    .layui-tab-content .line .addon-logo{width: 60px;margin-bottom: 10px;}

    .layui-tab-content .line .title {
        font-size: 18px;
        text-align: left;
        margin-bottom: 30px;
        color: #353535;
    }
    .layui-tab-content .line .info-item{
        margin-bottom: 5px;
    }
    .layui-tab-content .line .label {
        width: 84px;
        color: #9a9a9a;
        font-size: 14px;
        margin-right: 15px;
        text-align: left;
    }
    .layui-tab-content .line .value {
        width: 510px;
        color: #353535;
    }

    .layui-tab-content .empty-box .empty-tips {
        padding: 60px 0;
        text-align: center;
        font-size: 14px;
        color: #9a9a9a;
    }
</style>
{/block}